VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDownloadMaintenance"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'2004.10.19

Option Explicit

Private mcnDBFConn As ADODB.Connection
Private mcnSQLConn As ADODB.Connection
Private mblnOverwrite As Boolean

Private mstrDBFPath As String

Private strDL As String, strTranNo As String

Public Property Get oDBFConn() As ADODB.Connection
    Set oDBFConn = mcnDBFConn
End Property

Public Property Set oDBFConn(ByVal toNewDBFConn As ADODB.Connection)
    Set mcnDBFConn = toNewDBFConn
    mstrDBFPath = mcnDBFConn.DefaultDatabase
End Property

Public Property Get oSQLConn() As ADODB.Connection
    Set oSQLConn = mcnSQLConn
End Property

Public Property Set oSQLConn(ByVal toNewSQLConn As ADODB.Connection)
    Set mcnSQLConn = toNewSQLConn
End Property

Public Property Get lOverwrite() As Boolean
    lOverwrite = mblnOverwrite
End Property

Public Property Let lOverwrite(ByVal tblnNewOverwrite As Boolean)
    mblnOverwrite = tblnNewOverwrite
End Property

Public Function DownloadMaintenance() As Boolean
        
On Error GoTo TheSource
        
    'CLIENT
    ExtractRS "SELECT * FROM CLIENT WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT.itgm "
    ExtractRS "SELECT * FROM CLIENT_CUSTOMER WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_CUSTOMER.itgm "
    ExtractRS "SELECT * FROM CLIENT_CUSTOMER_CL WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_CUSTOMER_CL.itgm "
    ExtractRS "SELECT * FROM CLIENT_CUSTOMER_ADD WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_CUSTOMER_ADD.itgm "
    ExtractRS "SELECT * FROM CLIENT_SUPPLIER WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_SUPPLIER.itgm "
    ExtractRS "SELECT * FROM CLIENT_SUPPLIER_ITEM WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_SUPPLIER_ITEM.itgm "
    ExtractRS "SELECT * FROM CLIENT_SUPPLIER_ADD WHERE cCompanyID = '" & COID & "'", sFilePath & "CLIENT_SUPPLIER_ADD.itgm "
    
    'ITEM
    ExtractRS "SELECT * FROM ITEM WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM.itgm "
    ExtractRS "SELECT * FROM ITEM_C WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM_C.itgm "
    ExtractRS "SELECT * FROM ITEM_COSTLOG WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM_COSTLOG.itgm "
    ExtractRS "SELECT * FROM ITEM_SUB WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM_SUB.itgm "
    ExtractRS "SELECT * FROM ITEM_T WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM_T.itgm "
    ExtractRS "SELECT * FROM ITEM_W WHERE cCompanyID = '" & COID & "'", sFilePath & "ITEM_W.itgm "
    
    'SALESMAN
    ExtractRS "SELECT * FROM SALESMAN WHERE cCompanyID = '" & COID & "'", sFilePath & "SALESMAN.itgm "
    
    'WAREHOUSE
    ExtractRS "SELECT * FROM WHSE WHERE cCompanyID = '" & COID & "'", sFilePath & "WHSE.itgm "
    
    'MARKET SEGMENT & PRODUCT DIVISION
    ExtractRS "SELECT * FROM CLASSIFICATION WHERE cCompanyID = '" & COID & "'", sFilePath & "CLASSIFICATION.itgm "
    
    'USER PARAMETER
    ExtractRS "SELECT * FROM PARAMETER_USER WHERE cCompanyID = '" & COID & "'", sFilePath & "PARAMETER_USER.itgm "
    
    'PRODUCT GROUPINGS
    ExtractRS "SELECT * FROM GROUPINGS WHERE cCompanyID = '" & COID & "'", sFilePath & "GROUPINGS.itgm "
    
    
    'Audit trail
    UpdateLogFile "Downloading Maintenance", "ALL", "Downloaded"
        
TheSource:
    'There is not enough space on the disk.
    If Err.Number = -2147024784 Then
        MsgBox "There is not enough space on the disk.", vbExclamation, msgTtl
        Exit Function
    End If
    
End Function

Public Function FileExists(FileName As String) As Boolean
'The FileExists() function returns a value
'of TRUE if the specified file exists, or
'FALSE if it doesn't.
Dim Msg As String
' Turn on error trapping so error handler responds
' if any error is detected.
On Error GoTo CheckError
    FileExists = (Dir(FileName) <> "")
    ' Avoid executing error handler if no error occurs.
    Exit Function

CheckError:                 ' Branch here if error occurs.
' Define constants to represent intrinsic Visual Basic error
' codes.
Const mnErrDiskNotReady = 71, mnErrDeviceUnavailable = 68
' vbExclamation, vbOK, vbCancel, vbCritical, and vbOKCancel are
'constants defined in the VBA type library.
If (Err.Number = mnErrDiskNotReady) Then
    Msg = "Put a floppy disk in the drive and close the door."
    ' Display message box with an exclamation mark icon and with
    ' OK and Cancel buttons.
    If MsgBox(Msg, vbExclamation & vbOKCancel) = vbOK Then
        Resume
    Else
        Resume Next
    End If
ElseIf Err.Number = mnErrDeviceUnavailable Then
    Msg = "This drive or path does not exist: " & FileName
    MsgBox Msg, vbExclamation
    Resume Next
Else
    Msg = "Unexpected error #" & str(Err.Number) & " occurred: " _
    & Err.Description
    ' Display message box with Stop sign icon and OK button.
    MsgBox Msg, vbCritical
    Stop
End If
Resume
End Function

Private Sub ExtractRS(sCommandString As String, sFilePath As String)
Dim lcCmdString As String
Dim rsSet As ADODB.Recordset

    strTranNo = ""
    lcCmdString = sCommandString
        
    Set rsSet = oSQLConn.Execute(lcCmdString)
    If Not rsSet Is Nothing Then
        If (FileExists(sFilePath)) Then
            Kill sFilePath
        End If
        rsSet.Save sFilePath, adPersistADTG
    End If
    
    Set rsSet = Nothing
    
End Sub


